summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-01-02 00:26:29 -0700
committerMike Buland <eichlan@xagasoft.com>2012-01-02 00:26:29 -0700
commit0433eb31936fc72486e9a81732d5bcd38cf5808a (patch)
tree01f2a53e300af872350b700dbe8d4a0fa7fac38d
parent55e6f570f5760e970c6523458914b5e4c63a6ce4 (diff)
downloadstage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.gz
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.bz2
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.tar.xz
stage-0433eb31936fc72486e9a81732d5bcd38cf5808a.zip
Variables upconvert on add now.
It's not perfect, but it's decent for now, and early testing.
-rw-r--r--bloodfields.stage162
-rw-r--r--src/variable.cpp17
-rw-r--r--src/variable.h5
-rw-r--r--test.stage8
4 files changed, 189 insertions, 3 deletions
diff --git a/bloodfields.stage b/bloodfields.stage
new file mode 100644
index 0000000..81ff6e1
--- /dev/null
+++ b/bloodfields.stage
@@ -0,0 +1,162 @@
1game.title = "Bloodfields";
2
3global
4{
5 command: "quit"
6 {
7 exit();
8 }
9}
10
11situation <<start>>
12{
13 setup
14 {
15 player.hpMax = 10;
16 player.hpCur = player.hpMax;
17 player.xp = 0;
18 player.attack = 3;
19
20 global.bJustTravelled = false;
21
22 goto( <<field>> );
23 }
24}
25
26function status()
27{
28 display('You have ' + player.hpCur + ' of ' + player.hpMax + ' hp.');
29}
30
31function look()
32{
33 if( exists(global.enemy) )then
34 {
35 display('''You are standing in a field of wheat. You see a ''' +
36 global.enemy['name'] + ''' in front of you.''');
37 }
38 else
39 {
40 display('''You are standing in a field of wheat.''');
41 }
42// status();
43}
44
45function mkEnemy()
46{
47 global.enemy = {
48 'name': 'Snail',
49 'weapon': 'Tooth',
50 'attack': 3,
51 'hp': 5
52 };
53}
54
55function rollAttack( attack )
56{
57 return( random( attack-attack/3, attack+attack/3 ) );
58}
59
60function playerAttack()
61{
62 damage = rollAttack( player.attack );
63 global.enemy['hp'] = global.enemy['hp'] - damage;
64 display('You strike the ' + global.enemy['name'] + ' for ' + damage +
65 ' damage.');
66 if global.enemy['hp'] <= 0 then
67 {
68 display('You killed the ' + global.enemy['name'] + '!');
69 delete( global.enemy );
70 }
71}
72
73function enemyAttack()
74{
75 damage = rollAttack( global.enemy['attack'] );
76 player.hpCur -= damage;
77 display("The " + global.enemy['name'] + ' strikes you for ' + damage +
78 ' damage.');
79 if player.hpCur <= 0 then
80 {
81 display('The ' + global.enemy['name'] + ' killed you!');
82 exit();
83 }
84}
85
86situation <<travel>>
87{
88 enter
89 {
90 delete( global.enemy );
91
92 display('You wander aimlessly through the seemingly endless field of wheat.');
93
94 select = random(1,3);
95 if select == 1 then
96 {
97 mkEnemy();
98 display('''There's a ''' + global.enemy['name'] + ''' here!''');
99 }
100
101 global.bJustTravelled = true;
102
103 goto( <<field>> );
104 }
105}
106
107situation <<field>>
108{
109 command: "attack"
110 {
111 if exists(global.enemy) then
112 {
113 playerAttack();
114 goto( <<field>> );
115 }
116 else
117 {
118 display('''There's nothing here to attack...''');
119 }
120 }
121
122 command: "look"
123 {
124 look();
125 }
126
127 command: "walk"
128 {
129 if not exists(global.enemy) then
130 {
131 goto( <<travel>> );
132 }
133 else
134 {
135 display("You can't walk around with an enemy in front of you!
136 You can try to flee if you'd like...");
137 }
138 }
139
140 setup
141 {
142 look();
143 }
144
145 enter
146 {
147 if not global.bJustTravelled then
148 {
149 if exists( global.enemy ) then
150 {
151 enemyAttack();
152 }
153 status();
154// look();
155 }
156 else
157 {
158 }
159 global.bJustTravelled = false;
160 }
161}
162
diff --git a/src/variable.cpp b/src/variable.cpp
index a3fb4a2..965e1af 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -453,6 +453,16 @@ Variable Variable::operator+( const Variable &rhs ) const
453{ 453{
454 if( eType != rhs.eType ) 454 if( eType != rhs.eType )
455 { 455 {
456 Type eNew = bestType( eType, rhs.eType );
457
458 if( eType != eNew )
459 {
460 return to( eNew ) + rhs;
461 }
462 else
463 {
464 return *this + rhs.to( eNew );
465 }
456 throw VariableException("Adding between dissimilar types is not yet supported."); 466 throw VariableException("Adding between dissimilar types is not yet supported.");
457 } 467 }
458 else 468 else
@@ -868,6 +878,13 @@ void Variable::deinitType()
868 iValue = 0; 878 iValue = 0;
869} 879}
870 880
881Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const
882{
883 Type tBest = Bu::max( t1, t2 );
884
885 return tBest;
886}
887
871template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) 888template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k )
872{ 889{
873 switch( k.getType() ) 890 switch( k.getType() )
diff --git a/src/variable.h b/src/variable.h
index 8741b28..2eedcbb 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -28,12 +28,12 @@ public:
28 tBool, 28 tBool,
29 tInt, 29 tInt,
30 tFloat, 30 tFloat,
31 tString,
32 tSituation, 31 tSituation,
33 tVariable, 32 tVariable,
34 tVarPtr, 33 tVarPtr,
35 tList, 34 tList,
36 tDictionary 35 tDictionary,
36 tString,
37 }; 37 };
38 38
39public: 39public:
@@ -90,6 +90,7 @@ public:
90private: 90private:
91 void initType(); 91 void initType();
92 void deinitType(); 92 void deinitType();
93 Type bestType( Type t1, Type t2 ) const;
93 94
94private: 95private:
95 Type eType; 96 Type eType;
diff --git a/test.stage b/test.stage
index 3fe467c..66a9b70 100644
--- a/test.stage
+++ b/test.stage
@@ -17,7 +17,13 @@ situation <<start>>
17{ 17{
18 setup 18 setup
19 { 19 {
20 display( random( 1, 3 ) ); 20 stuff = {};
21 stuff['bob'] = {'joe': 'hi', 'sub': {1: 5, 2: 8} };
22 stuff['bob']['sub'][55] = "aoeu";
23 stuff['bob'] = 'hia';
24 stuff['joe'] = stuff['bob'];
25 stuff['joe'] += 'aoeu';
26 display( stuff['bob']['sub'][55] );
21 exit(); 27 exit();
22 } 28 }
23 29